'''
Created on May 7, 2011

@author: james
'''

from EvaluatorHelper import EvaluatorHelper

class ClinicEvaluator(object):
    '''
    '''

    def __init__(self, callIndex, clinicIndex, initCount):
        self._callIndex = callIndex
        self._clinicIndex = clinicIndex
        self._initCount = initCount
        
    def evaluate(self, chromosome, debug = False):

        counts = self._initCount.copy()
        
        lastClinicDoctor = -1
        
        maxScore = len(self._clinicIndex) - 1
        score = maxScore
        
        for index in self._clinicIndex:
            
            doctor = chromosome[index]
            counts[doctor] += 1
            
            '''
            is there anything wrong with having call on the evening of day after clinic?
            if index + 1 in self._callIndex:
                preCallDoctor = chromosome[index + 1]
                if preCallDoctor == doctor:
                    score -= 1
                    if debug: print "preCallDoctor == doctor, %d" % (doctor)
            ''' 
            
            if doctor == lastClinicDoctor:
                score -= 1
                if debug: print "doctor == lastClinicDoctor, %d" % (doctor)
                
            lastClinicDoctor = doctor
            
        if debug: print "Clinic counts: %s" % counts
        if debug: print "Max score: %d, score %d" % (maxScore, score)
        
        distScore = EvaluatorHelper.calculateDistributionPenalty(counts, len (self._clinicIndex), len (self._initCount), score)
        score -= distScore
        
        if debug: print "ClinicEvaluator dist penalty: %d, score: %d" % (distScore, score)
        
        return score
    
    def evaluateConvergenceCriteria(self, chromosome, attempt):
        return True
        
        
    